package utils;

import exceptions.ConfigException;
import vo.Config;

import java.io.*;
import java.util.Properties;

/**
 * @author Timur Yarosh
 *         Date: 28.05.13
 *         Time: 10:27
 */
public class ConfigurationReader {
    /**
     * @deprecated
     * @param path
     * @return
     * @throws IOException
     * @throws ConfigException
     */
    public static Config loadConfig(String path) throws IOException, ConfigException {
        Properties props = new Properties();
        InputStream config = new FileInputStream(path);
        try {
            props.load(config);
        } catch (IOException e) {
            throw new ConfigException(e.getMessage());
        }
        return new Config(props, new FileWriter(path));
    }

    /**
     *
     * @param path path on file system
     * @param storingPath path from PATHS class
     * @return
     * @throws IOException
     * @throws ConfigException
     */
    public static Config loadConfig(String path, String storingPath) throws IOException, ConfigException {
        Properties props = new Properties();
        InputStream config = new FileInputStream(path);
        try {
            props.load(config);
        } catch (IOException e) {
            throw new ConfigException(e.getMessage());
        }
        return new Config(props, storingPath);
    }
}
